package com.module.home.ui.scoringFactors.provider

import androidx.recyclerview.widget.RecyclerView
import com.chad.library.adapter.base.provider.BaseItemProvider
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.common.app.data.bean.home.ScoringClassListBean
import com.common.base.app.extras.otherwise
import com.common.base.app.extras.yes
import com.common.base.utils.ViewUtils
import com.common.base.utils.ViewUtils.getColor
import com.common.base.widget.CustomTextView
import com.module.ble.utils.AllCardTypeConfig
import com.module.home.R

/**
 *
 * 作者：sosou
 *
 * 版本：1.0
 *
 * 创建日期：2025/08/28
 *
 * 描述：评分因素-心率卡片
 *
 * 修订历史：
 *
 */
class ScoringFactorsHrCardProvider(
    override val itemViewType: Int = AllCardTypeConfig.TYPE_CARD_SF_HR,
    override val layoutId: Int = R.layout.home_scoring_factors_hr_crad_provider
) : BaseItemProvider<ScoringClassListBean>() {

    init {
    }

    override fun convert(helper: BaseViewHolder, item: ScoringClassListBean) {

        when (item.type) {
            "heart" -> {
                ViewUtils.setTextViewStartIcon(//动态设置drawableStart
                    helper.getView<CustomTextView>(R.id.tvLeftTitle),
                    R.drawable.common_grey_hr_icon
                )
                helper.setText(R.id.tvLeftTitle, R.string.common_heart_rate_hint)
            }

            "hrv" -> {
                ViewUtils.setTextViewStartIcon(//动态设置drawableStart
                    helper.getView<CustomTextView>(R.id.tvLeftTitle),
                    R.drawable.common_grey_hrv_icon
                )
                helper.setText(R.id.tvLeftTitle, R.string.common_hrv_hint)
            }

            "temperature" -> {
                ViewUtils.setTextViewStartIcon(//动态设置drawableStart
                    helper.getView<CustomTextView>(R.id.tvLeftTitle),
                    R.drawable.common_grey_body_temp_icon
                )
                helper.setText(R.id.tvLeftTitle, R.string.common_sleep_skin_temperature_hint)
            }

            "spo" -> {
                ViewUtils.setTextViewStartIcon(//动态设置drawableStart
                    helper.getView<CustomTextView>(R.id.tvLeftTitle),
                    R.drawable.common_grey_bo_icon
                )
                helper.setText(R.id.tvLeftTitle, R.string.common_blood_oxygen_saturation_hint)
            }

            "breath" -> {
                ViewUtils.setTextViewStartIcon(//动态设置drawableStart
                    helper.getView<CustomTextView>(R.id.tvLeftTitle),
                    R.drawable.common_grey_respiratory_rate_icon
                )
                helper.setText(R.id.tvLeftTitle, R.string.common_sleep_breathing_rate_hint)
            }

            else -> {
            }
        }

        helper.setGone(R.id.vLine, true)
        helper.setGone(R.id.hrv, true)
        when (item.status) {// 区分正常、无数据和异常 normal/no_data/anomalous
            "normal" -> {
                helper.setText(R.id.tvRightHint, R.string.common_pressure_normal_hint)
                helper.setTextColor(R.id.tvRightHint, getColor(R.color.product_color))
            }
            "anomalous" -> {
                helper.setText(R.id.tvRightHint, if("temperature"==item.type) R.string.common_compared_with_benchmark_value_hint else R.string.common_compared_with_past_days_hint)
                helper.setTextColor(R.id.tvRightHint, getColor(R.color.c_7f7f7f))

                helper.setGone(R.id.vLine, false)
                helper.setGone(R.id.hrv, false)
                val mAdapter = ScoringFactorsHrvItemAdapter(item.type)
                helper.getView<RecyclerView>(R.id.hrv).adapter = mAdapter
                mAdapter.setList(item.items)
            }
            else -> {
                helper.setText(R.id.tvRightHint, R.string.common_rail_unit)
                helper.setTextColor(R.id.tvRightHint, getColor(R.color.c_7f7f7f))
            }
        }
    }
}